///***********************************************************************************************************************
// 文 件 名: Example_GPIO.c
// 功    能: 输入输出测试
//
//
//
// 作    者：zhangzj
// 创建时间: 2024.03.18
//
// 日    志：
// [2024.03.18] 创建。
//***********************************************************************************************************************/
#include "NL8507.h"
#include "SM4.h"
extern uint8_t xdata KeyExp_w[4][4];

const unsigned char code plain_text[16] = {
  0x00,0x11,0x22,0x33,
  0x44,0x55,0x66,0x77,
  0x88,0x99,0xAA,0xBB,
  0xCC,0xDD,0xEE,0xFF
};
const unsigned char code key_text[16] = {
  0x00,0x01,0x02,0x03,
  0x04,0x05,0x06,0x07,
  0x08,0x09,0x0A,0x0B,
  0x0C,0x0D,0x0E,0x0F
};

//const unsigned char code ciphered_code [16] = {
//    0x69,  0xC4,  0xE0,  0xD8,
//    0x6A,  0x7B,  0x04,  0x30,
//    0xD8,  0xCD,  0xB7,  0x80,
//    0x70,  0xB4,  0xC5,  0x5A
//  };
//======================================================================================================================
// 名称：main
// 功能：
//
void main(void)
{
  char i;
  unsigned char *srcp;
//  unsigned char  data ciphered [16];
  unsigned char  data original [16];
  unsigned char  data ciphered [16] = {
  0x74,0xc0,0x46,0x04,
  0x81,0x61,0xbb,0xf3,
  0xd4,0xce,0xff,0x33,
  0xd3,0xf4,0x29,0xbe
};

  ////1.关狗
	WDTCN = 0x08;
	PCON0 = 0x30;
  PB2MD = 0xE0;
  PB3MD = 0xE0;
  PBDAT = 0x0C;
//  for(i=0;i<4;i++){
//    KeyExp_w[i][0] = key_text[(i<<2)+0];
//    KeyExp_w[i][1] = key_text[(i<<2)+1];
//    KeyExp_w[i][2] = key_text[(i<<2)+2];
//    KeyExp_w[i][3] = key_text[(i<<2)+3];
//  }
//  sm4_init();
//  for(i=0;i<32;i++)
//    SM4_KeyRound(i);

  // AES_Init();
   PBDAT = 0x00;
   srcp = SM4_Encryption(plain_text,key_text,1,1);
   PBDAT |= (0x01 << 2);
   for(i=0;i<16;i++){
     ciphered[i] = *(srcp+i);
   }
   PBDAT = 0x08;
   srcp = SM4_Encryption(ciphered,key_text,1,0);
   PBDAT = 0x0c;
   for(i=0;i<16;i++){
     original[i] = *(srcp+i);
   }
  // srcp = AES_Decryption(ciphered,key_text,1);
  // for(i=0;i<16;i++){
  //   original[i] = *(srcp+i);
  // }
  while(1);

}
